﻿using System;
using System.Drawing;
using System.Windows;
using System.Windows.Media.Imaging;
using Microsoft.Win32;
using Tesseract;

namespace Tesseract_ocr {
  /// <summary>
  /// MainWindow.xaml 的交互逻辑
  /// </summary>
  public partial class MainWindow: Window {
    public MainWindow() {
      InitializeComponent();
    }


    private void ButtonBase_OnClick(object sender, RoutedEventArgs e) {
      OpenFileDialog ofd = new OpenFileDialog();
      ofd.Filter = "图片|*.png;*.jpg|所有文件|*.*";
      ofd.Title = "请选择需要识别的图片";
      ofd.ShowDialog();

      Img.Source = new BitmapImage(new Uri(ofd.FileName));

      // 识别文字
      var img = new Bitmap(ofd.FileName);

      // 简体中文：chi_sim
      // 英文：eng
      var ocr = new TesseractEngine("tessdata", "eng", EngineMode.Default);
      var page = ocr.Process(img);
      OcrResult.Text = page.GetText();
    }
  }
}
